# 导包
import pytest

from api.add666 import add


# 在测试类的外面定义一个构造测试数据的方法
def build_data():
    # case01: 1 + 1 = 2 ==> (1, 1, 2)
    # case02: 1 + 0 = 1 ==> (1, 0, 1)
    # case03: 0 + 0 = 0 ==> (0, 0, 0)
    return [(1, 1, 2), (1, 0, 1), (0, 0, 0)]


def build_data2():
    test_data = []
    json_data = [
        {"a": 1, "b": 1, "c": 2},
        {"a": 1, "b": 0, "c": 1},
        {"a": 0, "b": 0, "c": 0}
    ]
    # 循环遍历json数据
    for i in json_data:
        aa = i.get("a")
        bb = i.get("b")
        cc = i.get("c")
        test_data.append((aa, bb, cc))
    # return [(1, 1, 2), (1, 0, 1), (0, 0, 0)]
    return test_data


# 引入参数化之后，运行代码时必须在类的外面


# 创建测试类
class TestAddAPI:
    @pytest.mark.parametrize("a, b, c", build_data2())
    def test(self, a, b, c):
        # 获取实际结果
        result = add(x=a, y=b)
        # 打印实际结果
        print(result)
        # 断言
        assert result == c
